const ajax = function (api) {
	return new Promise((resolve, reject) => {
		setTimeout(() => {
			if (api === 'api_1') { resolve('api_2'); }
			if (api === 'api_2') { resolve(100); }
		}, 0)
	})
}
async function getValue() {
	const api = await ajax('api_1');
	const value = await ajax(api);
	console.log(value);
	return value;
}
getValue();

async function foo() {
	return new Error('error');
}
foo().then(res => {
	console.log(res);
}).catch(err => {
	console.error(err);
})
async function foo2() {
	try {
		let v = await foo();
		console.log(v);
	} catch (e) {
		console.log(e);
	}
}
foo2();

const task = function (num) {
	return new Promise((resolve, reject) => {
		setTimeout(() => {
			if (num === 300) {
				reject('error');
			} else {
				resolve('imooc' + num);
			}
		}, 1000)
	})
}
async function foo3() {
	let task1 = task(100);
	let task2 = task(200);
	let task3 = task(300);
	let res1 = await task1.catch(err => console.log('res1', err));
	let res2 = await task2.catch(err => console.log('res2', err));
	let res3 = await task3.catch(err => console.log('res3', err));
}
foo3();
